package cc.edge2.sns.services;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jdo.PersistenceManager;

import net.arnx.jsonic.JSON;
import cc.edge2.sns.commons.PMF;
import cc.edge2.sns.models.Diary;
import cc.edge2.sns.models.FriendRelation;
import cc.edge2.sns.models.SNSUser;

import com.google.appengine.api.datastore.Text;

public class RegisterFriendService {
	public String execute(Map params, SNSUser user) {
		
		long currentUserId = Integer.parseInt((String)params.get("userId"));
		
		List<FriendRelation> list = new ArrayList<FriendRelation>();
		FriendRelation friendRelation1 = new FriendRelation(user.getUserId(), currentUserId);
		FriendRelation friendRelation2 = new FriendRelation(currentUserId, user.getUserId());
		list.add(friendRelation1);
		list.add(friendRelation2);
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try { 
			pm.makePersistentAll(list);
		} finally {
			pm.close();
		}
		
		
		Map<String, Object> result = new HashMap<String, Object>();
		Map<String, Object> contents = new HashMap<String, Object>();
		Map<String, Object> status = new HashMap<String, Object>();
		status.put("code", "0");
		status.put("message", "success");
		result.put("status", status);
		String value = JSON.encode(result);
		return value;
	}
}
